package com.codedancer.campus.manager.api.feedbackRecord;

import cn.hutool.core.bean.BeanUtil;
import com.baomidou.mybatisplus.core.metadata.IPage;
import com.codedancer.campus.common.anno.InterfacePermission;
import com.codedancer.campus.common.core.BaseApi;
import com.codedancer.campus.common.response.ApiResponse;
import com.codedancer.campus.manager.api.feedbackRecord.ro.FeedbackRecordPageSearchRo;
import com.codedancer.campus.manager.service.IFeedbackRecordService;
import com.codedancer.campus.manager.service.bo.feedbackRecord.FeedbackRecordPageSearchBo;
import com.codedancer.campus.manager.service.vo.feedbackRecord.FeedbackRecordPageVo;
import io.swagger.annotations.Api;
import io.swagger.annotations.ApiOperation;
import io.swagger.annotations.ApiParam;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.CrossOrigin;
import org.springframework.web.bind.annotation.DeleteMapping;
import org.springframework.web.bind.annotation.GetMapping;
import org.springframework.web.bind.annotation.PathVariable;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RequestMethod;
import org.springframework.web.bind.annotation.RestController;

@RestController
@RequestMapping("/api/feedback-record")
@CrossOrigin(methods = {RequestMethod.GET, RequestMethod.POST, RequestMethod.DELETE,
    RequestMethod.PUT}, maxAge = 3600)
@Api(value = "反馈记录Api", description = "反馈记录Api", tags = "反馈记录Api")
public class FeedbackRecordApi extends BaseApi {

    @Autowired
    private IFeedbackRecordService feedbackRecordService;

    @GetMapping("/page")
    @ApiOperation("分页查询反馈记录")
    @InterfacePermission(encodes = {"superAdmin","customerAdmin"})
    public ApiResponse<IPage<FeedbackRecordPageVo>> page(
        @ApiParam(value = "反馈记录分页查询Ro", required = false)
            FeedbackRecordPageSearchRo feedbackRecordPageSearchRo) {
        FeedbackRecordPageSearchBo feedbackRecordPageSearchBo = BeanUtil.copyProperties(
            feedbackRecordPageSearchRo, FeedbackRecordPageSearchBo.class);
        return success(feedbackRecordService.page(feedbackRecordPageSearchBo));
    }

    @DeleteMapping("/delete/{uuid}")
    @ApiOperation("删除反馈记录")
    @InterfacePermission(encodes = {"superAdmin","customerAdmin"})
    public ApiResponse<Void> delete(
        @PathVariable(value = "uuid", required = true) @ApiParam(value = "反馈记录类型uuid", required = true) String uuid) {
        feedbackRecordService.delete(uuid);
        return success();
    }
}
